<!-- Author: Moe Kyaw Thu Aung --> 
<!-- Last Modified: 11 Sep 2012 --> 
<?php 
	session_start();
	
	include("confs/config.php");
	
	if(count($_SESSION['cart']) < 1) {
		//include("checklogin.php");
		$_SESSION['empty'] = true;
		header("location: shopping.php");
		exit(0);
	}
	
	$conn = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
	mysql_select_db($DB_NAME, $conn);
?>
<html>
	<head>
		<title>My Book Store : Cart</title>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("#clear-cart").click(function() {
					return confirm("Are you sure, you want to clear your cart?");
				});
				$("td.action a").click(function() {
					return confirm("Are you sure, you want remove item from your cart?");
				});
			});
		</script>
	</head>
	<body>
		<div id="wrapper">
			<div id="head">
				<h1>My Book Store : Cart</h1>
			</div>
			
			<div id="content">
			
				<div id="cart-actions">
					<a href="shopping.php">Continue Shopping</a>
					<a href="order.php" id="order-now">Order Now!</a>
					
					<a href="actions.php?do=clear_cart" id="clear-cart">Clear Cart</a>
				</div>
				
				<div id="cart-content">
				
					<form action="actions.php?do=update_cart" method="post">
					<table id="view-cart" cellspacing="1" cellpadding="4">
				
						<tr>
							<th class='action'></th>
							<th>Price</th>
							<th>Quantity</th>
							<th>Sub-Total</th>
							<th class='action'></th>
						</tr>
				<?php error_reporting (E_ALL ^ E_NOTICE); ?>
					<?php
						foreach($_SESSION['cart'] as $id => $qty) {
							$result = mysql_query("SELECT * FROM items WHERE id = $id");
							$row = mysql_fetch_assoc($result);
							$id = $row['id'];
						
							echo "<tr>";
							echo "<td width='250px'><b>" . $row['name'] . "</b></td>";
							echo "<td>$" . $row['price'] . "</td>";
							echo "<td><input type='text' size='2' value='$qty' name='$id' /></td>";
							echo "<td>\$" . ($row['price'] * $qty) . "</td>";
							echo "<td class='action'><a href='actions.php?do=remove_item_from_cart&id=$id'><img src='admin/images/delete-color.png' /></a></td>";
							echo "</tr>";
						
							$total += ($row['price'] * $qty);
						}
					
						echo "<tr>";
						echo "<th align='right' colspan='3' style='padding:10px 4px;'>Total :</th>";
						echo "<td><b>\$$total</b></td>";
						echo "</tr>";
					?>
				
						<tr>
							<td colspan="4" align="right" class='action'>
								<input type="submit" value="Update Cart" />
							</td>
						</tr>
				
					</table>
					</form>
				
				</div>
				
			</div>
			
			<br /><br />
			
			<div id="foot">
				&copy; OneStop JCU.
			</div>
		</div>
	</body>
</html>
